package Sungjuk;

import java.util.Scanner;


public class SungJukService implements ISungjukService{
	private SungJukDAO sjdao;
	public SungJukService() {
		sjdao = new SungJukDAO();
	}
	
	@Override
	public void creatSungJuk() {
		Scanner sc = new Scanner(System.in);
		SungjukVO sj = new SungjukVO();
		System.out.println("성적 입력란");
		System.out.println("이름을 입력해 주세요~");
		sj.setName(sc.next());
		System.out.println("국어성적을 입력해 주세요");
		sj.setKor(sc.nextInt());
		System.out.println("영어성적을 입력해 주세요");
		sj.setEng(sc.nextInt());
		System.out.println("수학성적을 입력해 주세요");
		sj.setMat(sc.nextInt());
		sj.setTot(this.totalSungJuk(sj.getKor(),sj.getEng(),sj.getMat()));
		sj.setAvg(this.avgSungJuk(sj.getTot()));
		sj.setGra(this.graSungJuk(sj.getAvg()));
		
		if (sjdao.insertSungJuk(sj))
			System.out.println("성공");
		else
			System.out.println("실패");
	}
	@Override
	public void readSungJuk() {
		for(SungjukVO sj:sjdao.selectSungJuk()){

			System.out.print(sj.getSjno());
			System.out.print("/");
			
			System.out.print(sj.getName());
			System.out.print("/");
			System.out.print(sj.getEng());
			System.out.print("/");
			System.out.print(sj.getKor());
			System.out.print("/");
			System.out.print(sj.getMat());
			System.out.print("/");
			System.out.print(sj.getTot());
			System.out.print("/");
			System.out.print(sj.getAvg());
			System.out.print("/");
			System.out.println(sj.getGra());
			
			}
		
	}
	

	@Override
	public int totalSungJuk(int kor, int eng, int mat) {
		return kor + eng + mat;
	}

	@Override
	public float avgSungJuk(int tot) {
		return tot/3;
	}

	@Override
	public String graSungJuk(float avg) {
		switch((int)avg/10){
		case 10 :
		case 9 : return "수";
		case 8 : return "우";
		case 7 : return "미";
		case 6 : return "양";
		default : return "가";
		}
	}

	@Override
	public void modifySungJuk() {
		Scanner sc =new Scanner(System.in);
		SungjukVO sjvo = new SungjukVO();
		readSungJuk();
		System.out.println("수정할 내용을 입력해 주세요");
		System.out.println("수정할 분의 성함을 입력해 주세요");
		sjvo.setName(sc.next());
		System.out.println("국어점수");
		sjvo.setKor(sc.nextInt());
		System.out.println("영어점수");
		sjvo.setEng(sc.nextInt());
		System.out.println("수학점수");
		sjvo.setMat(sc.nextInt());
		
		sjvo.setTot(this.totalSungJuk(sjvo.getKor(),sjvo.getEng(),sjvo.getMat()));
		sjvo.setAvg(this.avgSungJuk(sjvo.getTot()));
		sjvo.setGra(this.graSungJuk(sjvo.getAvg()));
		/*System.out.println("총점수");
		sjvo.setTot(sc.nextInt());
		System.out.println("평균점수");
		sjvo.setAvg(sc.nextFloat());
		System.out.println("성적");
		sjvo.setGra(sc.next());
		System.out.println("");*/
		
		if(sjdao.updateSungJuk(sjvo))
			System.out.println("수정성공");
		else
			System.out.println("수정실패");
		readSungJuk();
	}
	
	
	
}
